<?php
/* @var $this BackendController */
/* @var $model User */
/* @var $form TActiveForm */
?>
<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->theme->baseUrl.'/js/form-validator.js',CClientScript::POS_HEAD)?>
<div class="form" style="padding:5px">

<?php $form=$this->beginWidget('TActiveForm', array(
	'id'=>'user-form',
    'htmlOptions' =>array('enctype'=>"multipart/form-data" ),
    //'focus'=>array($model,'name'),

    // Please note: When you enable ajax validation, make sure the corresponding
	// controller action is handling ajax validation correctly.
	// There is a call to performAjaxValidation() commented in generated controller code.
	// See class documentation of CActiveForm for details on this.
    'enableAjaxValidation'=>true,
    'enableClientValidation'=>true,
    'clientOptions'=>array(
        'afterValidate'=>'js:afterValidate',
        'validateOnSubmit'=>true,
        'validateOnType'=>true,
        'validateOnChange'=>true,
        'hideErrorMessage'=>true
    ),
)); ?>
    <div class="alert alert-info">
       <?php echo Yii::t('UserModule.base','Fields with')?><span class="required"> * </span> <?php echo Yii::t('UserModule.base','are required.')?>
    </div>

<?php if(!$model->isNewRecord):?>
    <div class="avatar">
        <?php echo $form->labelEx($model,'avatar',array('style'=>'margin-left:30px;')); ?>
        <?php echo CHtml::decode($model->getAvatar())?>
        <?php echo $form->error($model,'avatar'); ?>
    </div>
    <br />
<?php endif;?>

    <div class="input-group">
		<?php echo $form->labelTb($model,'name'); ?>
		<?php echo $form->textFieldTb($model,'name'); ?>
        <?php echo $form->error($model,'name',array('afterValidateAttribute'=>'js:afterValidateAttribute')); ?>
	</div>

    <div class="input-group">
		<?php echo $form->labelTb($model,'login'); ?>
		<?php echo $form->textFieldTb($model,'login'); ?>
		<?php echo $form->error($model,'login',array('afterValidateAttribute'=>'js:afterValidateAttribute')); ?>
	</div>

    <div class="input-group">
		<?php echo $form->labelTb($model,'email'); ?>
		<?php echo $form->textFieldTb($model,'email'); ?>
		<?php echo $form->error($model,'email',array('afterValidateAttribute'=>'js:afterValidateAttribute')); ?>
	</div>

<?php if($model->isNewRecord):?>
    <div class="input-group">
		<?php echo $form->labelTb($model,'password'); ?>
		<?php echo $form->passwordFieldTb($model,'password'); ?>
		<?php echo $form->error($model,'password',array('afterValidateAttribute'=>'js:afterValidateAttribute')); ?>
	</div>
<?php endif;?>

    <div class="well well-sm">
		<?php echo $form->labelEx($model,'role'); ?>
		<?php echo $form->dropDownList($model,'role',$model->getRoleOptions(),array('style'=>'padding:1px;')); ?>
		<?php echo $form->error($model,'role'); ?>

        <?php echo $form->labelEx($model,'active'); ?>
        <?php echo $form->dropDownList($model,'active',$model->getActiveDropdownData()); ?>
        <?php echo $form->error($model,'active'); ?>


        <?php echo $form->labelEx($model,'avatar'); ?>
        <?php echo CHtml::activeFileField($model, 'avatar'); ?>
        <?php echo $form->error($model,'avatar'); ?>
	</div>


    <div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? Yii::t('UserModule.base','Create') : Yii::t('UserModule.base','Save'),array('class'=>'btn btn-primary')); ?>
	</div>

<?php $this->endWidget(); ?>
</div><!-- form -->